#include "task.h"

void USART1_IRQHandler(void)
{
    u8 res;
    if(!(USART1->SR & (1<<5))) return;
    res =USART1->DR & 0x1FF;
    if(!Data_Receive_Precess(res))
        RcvCnt++;
}

void DMA1_Channel4_IRQHandler(void)
{
    if(!(DMA1->ISR & (1<<13))) return;
    DMA1->IFCR |= 1<<13;
    DMA_Buffer_Clear();
    DMA1_Channel4->CCR &=~ (1<<0);
}

void TIM2_IRQHandler(void)
{
    s16 TIM_Period;
    if (!(TIM2->SR & TIM_IT_Update)) return;
    if (!PWM_Generate(0, &TIM_Period)) TIM2->CR1 &=~ TIM_CR1_CEN;
    if (TIM_Period) TIM2->ARR = TIM_Period;
    TIM2->SR = ~TIM_IT_Update;
}
void TIM3_IRQHandler(void)
{
    s16 TIM_Period;
    if (!(TIM3->SR & TIM_IT_Update)) return;
    if (!PWM_Generate(1, &TIM_Period)) TIM3->CR1 &=~ TIM_CR1_CEN;
    if (TIM_Period) TIM3->ARR = TIM_Period;
    TIM3->SR = ~TIM_IT_Update;
}
void TIM4_IRQHandler(void)
{
    s16 TIM_Period;
    if (!(TIM4->SR & TIM_IT_Update)) return;
    if (!PWM_Generate(2, &TIM_Period)) TIM4->CR1 &=~ TIM_CR1_CEN;
    if (TIM_Period) TIM4->ARR = TIM_Period;
    TIM4->SR = ~TIM_IT_Update;
}
void TIM5_IRQHandler(void)
{
    s16 TIM_Period;
    if (!(TIM5->SR & TIM_IT_Update)) return;
    if (!PWM_Generate(3, &TIM_Period)) TIM5->CR1 &=~ TIM_CR1_CEN;
    if (TIM_Period) TIM5->ARR = TIM_Period;
    TIM5->SR = ~TIM_IT_Update;
}
void TIM6_IRQHandler(void)
{
    s16 TIM_Period;
    if (!(TIM6->SR & TIM_IT_Update)) return;
    if (!PWM_Generate(4, &TIM_Period)) TIM6->CR1 &=~ TIM_CR1_CEN;
    if (TIM_Period) TIM6->ARR = TIM_Period;
    TIM6->SR = ~TIM_IT_Update;
}
void TIM7_IRQHandler(void)
{
    s16 TIM_Period;
    if (!(TIM7->SR & TIM_IT_Update)) return;
    if (!PWM_Generate(5, &TIM_Period)) TIM7->CR1 &=~ TIM_CR1_CEN;
    if (TIM_Period) TIM7->ARR = TIM_Period;
    TIM7->SR = ~TIM_IT_Update;
}
